// import AvatarUpload from './AvatarUpload.vue';
import type { FormSchema } from '@/components/core/schema-form/';
import Api from '@/api';
import { Gender } from '@/enums';

export const userSchemas: FormSchema<UserOut>[] = [
  // {
  //   field: 'avatar',
  //   component: () => AvatarUpload,
  //   label: '头像',
  // },
  {
    field: 'deptId',
    component: 'TreeSelect',
    label: '所属部门',
    componentProps: {
      fieldNames: {
        label: 'deptName',
        value: 'id',
      },
      getPopupContainer: () => document.body,
    },
    rules: [{ required: false, type: 'string' }],
  },
  {
    field: 'roleIds',
    component: 'Select',
    label: '所属角色',
    rules: [{ required: false, type: 'array' }],
    componentProps: {
      mode: 'multiple',
      allowClear: true,
      showArrow: true,
      request: async () => {
        const { items = [] } = await Api.systemRole.roleList({});
        return items.map((n) => ({ label: n.name, value: n.id }));
      },
      getPopupContainer: () => document.body,
      filterOption: (input, option) => 
        option?.label?.toString().toLowerCase().includes(input.toLowerCase()),
    },
    defaultValue: [],
  },
  {
    field: 'userName',
    component: 'Input',
    label: '用户名',
    rules: [{ required: true }],
  },
  // {
  //   field: 'password',
  //   label: '密码',
  //   component: 'InputPassword',
  //   componentProps: {
  //     placeholder: '无需修改请留空',
  //   },
  //   rules: [{ required: true }],
  // },

  {
    field: 'realName',
    component: 'Input',
    label: '真实名',
    colProps: {
      span: 12,
    },
    rules: [{ required: true }],
  },
  {
    field: 'mobile',
    component: 'Input',
    label: '手机',
    colProps: {
      span: 12,
    },
    rules: [{ required: true }],
  },
  {
    field: 'email',
    component: 'Input',
    label: '邮箱',
    colProps: {
      span: 12,
    },
    rules: [{ type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }],
  },
  {
    field: 'gender',
    component: 'RadioGroup',
    label: '姓别',
    defaultValue: Gender.Male,
    componentProps: {
      options: [
        {
          label: '男',
          value: Gender.Male,
        },
        {
          label: '女',
          value: Gender.Female,
        },
      ],
    },
  },
  {
    field: 'active',
    component: 'RadioGroup',
    label: '状态',
    defaultValue: true,
    componentProps: {
      options: [
        {
          label: '启用',
          value: true,
        },
        {
          label: '禁用',
          value: false,
        },
      ],
    },
  },
];
/**
 * @description 更新用户密码
 */
export const updatePswSchemas: FormSchema[] = [
  {
    field: 'password',
    component: 'Input',
    label: '新密码',
    rules: [{ required: true, type: 'string' }],
  },
];
/**
 * @description 将用户转移部门
 */
export const transferUserSchemas: FormSchema[] = [
  {
    field: 'departmentId',
    component: 'TreeSelect',
    label: '转移至',
    rules: [{ required: true, type: 'number' }],
  },
];
